package com.luoc.service.impl;

import com.luoc.service.Component;

import java.util.ArrayList;

/**
 * @Author: luoc
 * @Date: 2019/9/19 16:09
 */
public class Composite extends Component {
    private ArrayList<Component> list = new ArrayList<Component>();

    @Override
    public void add(Component component) {
            list.add(component);
    }

    @Override
    public void remove(Component component) {
            list.remove(component);
    }

    @Override
    public Component getChild(int i) {
        return list.get(i);
    }

    @Override
    public void operation() {
        // 容器构建具体业务实现
        // 递归调用成员构建的业务方法
        for (Object obj : list
        ) {
            ((Component) obj).operation();
        }
    }
}
